<?php
/**
 * Class descript.
 * User: chan
 * Date: 2017/8/16 17:47
 */
namespace WeChat;
class Application
{
    private $token = "";
    public function run($options)
    {
        $this->token = $options['token'];
        $News = new News();
        $News->responseMsg();

        /*$echostr = input("echostr");
         if(isset($echostr)){
             //验证微信
             $this->valid();
         }else{
             //回复消息
           $News = new News();
           $News->responseMsg();
         }*/
    }
    public function valid()
    {
        $echoStr = input("get.echostr");
        if($this->checkSignature()){
            echo $echoStr;
            exit;
        }
    }

    private function checkSignature()
    {

        $signature = input("get.signature");
        $timestamp = input("get.timestamp");
        $nonce = input("get.nonce");

        $tmpArr = array($this->token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );
        if( $tmpStr == $signature ){
            return true;
        }else{
            return false;
        }
    }

}